# define analogPin 5
const byte interruptPump = 2;  //2号控制泵的启停
const byte interruptMode = 3;  //3号控制拉伸压缩
const byte interruptMusc = 4;  //4号切换两个肌肉

const byte jMode = A0;//A0输出拉伸压缩的两个泵
const byte jPump = A1;//A1输出信号控制泵的启停
const byte jMusc = A2;//A控制不同肌肉的切换

volatile byte stateMusc = LOW;//控制不同肌肉切换
volatile byte stateMode = LOW;//控制不同模式切换
int statePump = 0;

void setup() {
  //output负责输出信号到继电器控制各个部件的启停
  pinMode(jMusc,OUTPUT);
  pinMode(jPump,OUTPUT);
  pinMode(jMode,OUTPUT);
  
  //将中断触发引脚 三个开关分别设置为INPUT_PULLUP（输入上拉）模式 

  pinMode(interruptPump, INPUT_PULLUP);  
  pinMode(interruptMode, INPUT_PULLUP); 
  pinMode(interruptMusc, INPUT_PULLUP); 

  //设置串口初始频率
 Serial.begin(9600);
 
  //设置3个中断触发程序，都是当检测到高电平时触发,aeduino只有两个中断可以用
  attachInterrupt(digitalPinToInterrupt(interruptPump), pumpControl, RISING);
  attachInterrupt(digitalPinToInterrupt(interruptMode), modeControl, RISING);
  //attachInterrupt(digitalPinToInterrupt(interruptMusc), muscControl, RISING);
}

void loop(){
  //首先判断控制模式
 
    digitalWrite(jMode, stateMode);
    Serial.print(stateMode);
    Serial.print(" ");
  //  int temp = digitalRead(interruptMusc);

   //判断泵的启停,按下按钮即给泵供电1秒钟
    if(statePump==1){
      Serial.println("1");
      digitalWrite(jPump,HIGH);
      delay(1200); 
      statePump=0;
      digitalWrite(jPump,LOW);
}
    Serial.println(statePump);
    statePump=0;
    digitalWrite(jPump,LOW);
  
  }
void modeControl(){
  stateMode=!stateMode;//切换两个肌肉，只需要切换输出高低电平就可以；初始状态就是LOW就好
  }
void pumpControl(){
  statePump=1;
}
/*
void muscControl(){
  Serial.println("yes");
  stateMusc=-stateMusc;
}*/



























































/* 
  digitalWrite(pumpPin,HIGH);//启动泵
  delay(1300);
  
  
  }
void loop() {
 // digitalWrite(ledPin, state);
//  Serial.println(state);
  analogWrite(analogPin,255);  
  Serial.println(analogPin);
 // delay(500);
 // analogWrite(analogPin,100);
}
 
//中断服务程序
void blink() {  
  state = !state;
}

///*#define A0 A0*/
//int analogInput[6] = {A0, A1, A2, A3, A4, A5};
//const byte interruptP=2;
//bool state = LOW;
//void setup(){
//  pinMode(A0, OUT                                                                                                                                                                                                                                                                                                                                                                             PUT); 
//  pinMode(interruptP,INPUT);
//  Serial.begin(9600);
//  attachInterrupt(0,inter1,RISING);
//}
//void d1(){
//   digitalWrite(A0, HIGH);
//   delay(5000);
//   digitalWrite(A0,LOW);
//}
//void button(){
//   digitalWrite(A0, HIGH);
//  state=!state; 
//}\
//
//
//int cnt=0;
//void loop(){
//    digitalWrite(A0,LOW); 
//    Serial.print(A0);
//    Serial.print(" ");
//    Serial.println(interruptP);
////  while(1){
////      cnt++;
////      if(cnt<=8){
////        digitalWrite(A0, HIGH);  
////        delay(200);
////        digitalWrite(A0,LOW);
////        delay(1000);
////      }
////      else{
////          cnt=6;
////          break;
////        }
////  }
//
//  
//}*/
